package gui.awt;

import java.awt.*;

/**
 * GridLayout       网格布局管理器
 * 使容器中各个组件呈网格状布局，平均占据容器的空间
 * */
public class GridLayoutDemo {
    public static void main(String[] args) {
        FrameDemo frame = new FrameDemo("GridLayout");
        GridLayout gl = new GridLayout(3,2,5,5);
                                // 设置网格为3行2列排列，网格横向间距为5个像素，纵向间距为5个像素
        frame.setLayout(gl);    // 设置frame的布局为GridLayout
        Color[] colors = {Color.cyan, Color.gray, Color.yellow, Color.red, Color.green};
        for(int i = 0; i < 5; i++) {
            Button btn = new Button("button" + (i + 1));
            btn.setBackground(colors[i]);
            frame.add(btn);
        }
        frame.setVisible(true);
    }
}
